package com.aspira.service;

import com.aspira.entity.Order;
import com.aspira.entity.OrderItem;
import com.aspira.mapper.OrderItemRepository;
import com.aspira.mapper.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
public class DemoService {

    @Autowired
    private OrderRepository orderRepository;

    @Autowired
    private OrderItemRepository orderItemRepository;

    @Transactional
    public Order insert(Order order, OrderItem orderItem){
//        Order order = new Order();
//        order.setUserId(51);
//        order.setStatus("INSERT_TEST");
//        System.out.println("before order: "+ order.getOrderId());
        int insert = orderRepository.insert(order);
//        assertTrue(insert > 0);
//        System.out.println("after orderId: "+order.getOrderId());

        long orderId = order.getOrderId();
//
//
//        OrderItem item = new OrderItem();
//        item.setOrderId(orderId);
//        item.setUserId(51);
//        item.setStatus("INSERT_TEST");
        orderItem.setOrderId(orderId);
        orderItemRepository.insert(orderItem);

        return order;
    }

    public List<Order> getAll() {
        return  orderRepository.getAll();
    }

    public Integer countAll() {
        return  orderRepository.countAll();
    }

    public Integer delete(Order order){
        return  orderRepository.delete(order);
    }

}
